import request from '../request';
import { ElMessage } from 'element-plus';

export const getDeptTree = async () => {
  const data = await request.get('/auth/dept/list/5');
  return data.data;
};

export const getDeptInfo = async (deptId) => {
  const data = await request.get(`/auth/dept/info/${deptId}`);
  return data.data;
};

/**
 * 新增部门
 * @returns null
 */
export const addDept = async (commitForm) => {
  const data = await request.post('/auth/dept/add', commitForm);
  if (data.code !== 100) ElMessage.success('新增部门成功');
};

/**
 * 修改部门
 * @returns null
 */
export const updateDept = async (commitForm, id) => {
  const data = await request.put(`/auth/dept/update/${id}`, commitForm);
  if (data.code !== 100) ElMessage.success('修改部门成功');
};

/**
 * 删除部门
 * @returns null
 */
export const deleteDept = async (ids) => {
  const data = await request.delete(`/auth/dept/delete/${ids}`);
  if (data.code !== 100) ElMessage.success('删除部门成功');
};

/**
 * 验证部门名称是否重复
 * @returns Object
 */
export const validateDept = async (searchForm) => {
  const data = await request.get('/auth/dept/validate', {
    params: searchForm,
  });
  return data;
};
